package me.xiaoyan.cloud.controller;

import me.xiaoyan.cloud.pojo.UserInfo;
import me.xiaoyan.cloud.service.UserLoginService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class LoginController {
    @Resource
    private UserLoginService userLoginService;
    @PostMapping("/login")
    public UserInfo login(@RequestBody  UserInfo userinfo){
        if(StringUtils.hasLength(userinfo.getAccount()) && StringUtils.hasLength(userinfo.getPassword())) {
            return userLoginService.login(userinfo);
        }
        throw new RuntimeException("参数不正确");
    }
    @PostMapping("/signup")
    public UserInfo signup(@RequestBody UserInfo userinfo){
        return userLoginService.signup(userinfo);
    }
}
